package com.android.justcook;

import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TabHost;
import android.widget.TextView;
import camp.android.justcook.R;

public class ShowRecipeActivity extends BaseActivity{
	
	protected int REC_ID;
	protected boolean REC_FAV = false;
	protected String USER_LEVEL_NAME;
	protected int USER_POINTS;
	protected int catID;
	
	
	protected void onCreate(Bundle bundle)
	{				
		Intent intent = getIntent();
		catID = intent.getIntExtra("CATEGORY_ID",0);			
		if(!getIntent().hasExtra("CATEGORY_ID")) throw new IllegalStateException();
		REC_ID = intent.getIntExtra(RecipesList.EXTRA_MESSAGEQ, 0);

		String REC_INGREDIENTS = MainActivity.MEALS_INGRIDIENTS[catID][REC_ID];
		String REC_METHOD = MainActivity.MEALS_METHOD[catID][REC_ID];
		int REC_PIC = MainActivity.MEALS_IMAGES[catID][REC_ID];
		String REC_POINTS = MainActivity.MEALS_POINTS[catID][REC_ID] ;
		String REC_NAME = MainActivity.MEALS[catID][REC_ID] ;
		setContentView(R.layout.show_recipe);
		//setContentView(R.layout.progress_bar);
		
		ProgressBar pb = (ProgressBar) findViewById(R.id.progress_bar);
		pb.setProgress(50);
		//pb.setVisibility(View.VISIBLE);
		
		
		TabHost tabs = (TabHost) findViewById(R.id.tabs)
				;
		tabs.setup();
		
		
		tabs.addTab(tabs.newTabSpec("Ingredients").setContent(R.id.ingredients).setIndicator("Ingredients"));
		tabs.addTab(tabs.newTabSpec("Method").setContent(R.id.method).setIndicator("Method"));
		
		TextView name = (TextView) findViewById(R.id.cover_category);
		name.setText(REC_NAME);
		
		TextView ingredients = (TextView) findViewById(R.id.text_ingredients);
		ingredients.setText(REC_INGREDIENTS);
		
		TextView method = (TextView) findViewById(R.id.text_method);
		method.setText(REC_METHOD);
	
		ImageView img = (ImageView) findViewById(R.id.imageView1);
		img.setBackgroundResource(REC_PIC);
		
		TextView points = (TextView) findViewById(R.id.rec_points);
		points.setText(String.valueOf(REC_POINTS) + " pts");
		
		ImageButton fav = (ImageButton) findViewById(R.id.favorite);
		if(REC_FAV)
			fav.setBackgroundResource(R.drawable.starfull);
		else	fav.setBackgroundResource(R.drawable.starempty);
		
		ActionBar actionBar = getActionBar();
	    actionBar.setDisplayHomeAsUpEnabled(true);
	    actionBar.setTitle(MainActivity.MEALS[catID][REC_ID]);
	    
	    super.onCreate(bundle);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch (item.getItemId()) {
	        case android.R.id.home:
	        	
	            Intent intent = new Intent(this, RecipesListActivity.class);
	            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	            intent.putExtra(MainActivity.EXTRA_MESSAGE, catID);
	            startActivity(intent);
	            return true;
	        default:
	            return super.onOptionsItemSelected(item);
	    }
	}
	
	public void startListening(View view)
	{
		Intent intent = new Intent(this, ReadStepActivity.class);
		intent.putExtra("rec_id", REC_ID);
		intent.putExtra(MainActivity.EXTRA_MESSAGE, catID);
		startActivity(intent);
	}
	
	public void onToggleStar(View view)
	{
		ImageButton fav = (ImageButton) findViewById(R.id.favorite);
		if(REC_FAV)
		{
			fav.setBackgroundResource(R.drawable.starfull);
			REC_FAV = false;
		}
		else
		{
			fav.setBackgroundResource(R.drawable.starempty);
			REC_FAV = true;
		}
	}
}
